package map;

import java.util.HashMap;
import java.util.Map;

public class CountNumberOfPairsWithAbsoluteDifferenceK2006 {
    public int countKDifference(int[] nums, int k) {
        Map<Integer,Integer> map = new HashMap<>();
        int result = 0;
        for (int i = 0; i < nums.length; i++) {
            result+=map.getOrDefault(nums[i]+k,0);
            result+=map.getOrDefault(nums[i]-k,0);
            map.put(nums[i],map.getOrDefault(nums[k], 0)+1);
        }
        return result;
    }
}
